Skip to content

Remove unused Promise polyfill and promise dependency - #57777

Open
aravi365 wants to merge 1 commit into
react:mainfrom
aravi365:remove-promise-polyfill
Open

Remove unused Promise polyfill and promise dependency#57777
aravi365 wants to merge 1 commit into
react:mainfrom
aravi365:remove-promise-polyfill

Conversation

@aravi365

@aravi365 aravi365 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #57702.

polyfillPromise.js requires ../Promise when HermesInternal.hasPromise() is falsy. Metro can't know that condition at build time, so it bundles the require anyway and the promise package ends up in every app bundle even though Hermes apps never reach that branch.

This drops the fallback branch, Libraries/Promise.js, the promise dependency and its flow-typed def.

DEV unhandled-rejection tracking is unaffected, that goes through HermesInternal.enablePromiseRejectionTracker. promiseRejectionTrackingOptions.js was importing its options type from promise/setimmediate/rejection-tracking, so I've declared that type inline.

Open question: this also drops the fallback for non-Hermes engines (JSC, V8). Both have had a native Promise for years and the "Event loop not supported" case the fallback was written for is long gone, but it is still a behavior change, so your call.

Both internal checks are red and I can't see the logs from out here. If something internal still imports Libraries/Promise or promise directly, I can cut this down to just deleting the else branch and leave the file and the dependency in place. That still keeps promise out of the bundle, which is what the issue is about. Say the word and I'll push it.

Changelog:

[GENERAL] [REMOVED] - Remove the unused Promise polyfill and the promise dependency

Test Plan

  • No references to Libraries/Promise or promise/setimmediate are left anywhere in the repo.
  • Only the promise line is removed from package.json.
  • Hermes behavior is unchanged. hasPromise() is true there, so global.Promise was already what apps used, and the DEV rejection tracker still gets the same options object.

I have not run the JS suite locally, relying on CI for test_js, Flow and lint.

Every supported JS engine ships a native Promise, but the polyfill
branch in polyfillPromise.js is statically reachable, so Metro bundles
the promise package into every app even though it is never used.
Remove the dead branch, Libraries/Promise.js and the promise
dependency. DEV unhandled-rejection tracking is unchanged.

Fixes react#57702
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 31, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 31, 2026
@meta-codesync

meta-codesync Bot commented Jul 31, 2026

Copy link
Copy Markdown

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D114354694.

@aravi365

Copy link
Copy Markdown
Contributor Author

@robhogan you imported this on 31 Jul and both internal checks have been red since. I can't see the internal logs from out here, so I'm guessing: is something in the internal codebase still importing Libraries/Promise or the promise package?

Happy to narrow this if it helps. I can keep the polyfill and gate it so only non-Hermes engines load it, which leaves any internal call sites working while still keeping promise out of Hermes bundles. Or I can split it so this PR only drops the dead branch and leaves the dependency in place.

Let me know which you'd prefer and I'll push it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

polyfillPromise.js imports a promise package that never used as hasPromise() is always true

1 participant